import pymssql,json

# server    数据库服务器名称或IP
# user      用户名
# password  密码
# database  数据库名称

server = "www.yangkeqiang.top:1433"
user = "sa"
password = "123abc###"
database = "BSR2021"
conn = pymssql.connect(server, user, password, database)
cursor = conn.cursor()

def Select_MB001(bill_no):
    sql = "SELECT 品号,SUM(进货数量) FROM ALEX_PRINT_BT WHERE 单号 = '%s' GROUP BY 品号" % (bill_no)
    cursor.execute(sql)
    bill_info = []
    row = cursor.fetchone()
    while row:
        bill_info.append({'MB001':row[0],'num':float(row[1])})
        row = cursor.fetchone()
    return json.dumps(bill_info)

